package name.as3.SpriteMirror
{
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.geom.Point;
	
	import name.as3.geom.Line;

	public class MirrorSprite extends Sprite
	{
		private var m_obPointA:ControlPoint ;
		private var m_obPointB:ControlPoint ;
		private var m_nPointSize :int = 9 ;
		private var m_nLineOfset:int = 2 ;
		private var m_nLineThick:int = 2 ;
		private var m_nMirrorColor:int = 0x00ff99 ;
		private var m_nBackColor: int = 0  ;
		private var m_arrObject:Array = [] ;
		/**∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥构造函数
		 */		
		public function MirrorSprite()
		{
			super();
			m_obPointA = new ControlPoint(this ) ;
			m_obPointB = new ControlPoint(this) ;
			m_obPointA.width = m_obPointB.width = m_nPointSize ;
			super.addChild(m_obPointA ) ;
			super.addChild(m_obPointB ) ;
			
		}
		/**
		 *∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥对象添加函数 
		 * @param obj
		 * 
		 */		
		public function add(obj:DisplayObject):void
		{
			if(obj!=null)
			{
				if(m_arrObject.indexOf(obj)==-1)
				{
					m_arrObject.push(obj) ;
				}
			}
		}
		/**
		 *∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥镜面刷新函数 
		 * 
		 */		
		public function updateMirror():void
		{
			graphics.clear() ;
			graphics.lineStyle(m_nLineThick , m_nMirrorColor ) ;
			graphics.moveTo(m_obPointA.x , m_obPointA.y) ;
			graphics.lineTo(m_obPointB.x , m_obPointB.y ) ;
			var obPointA:Point = new Point(m_obPointA.x , m_obPointA.y );
			var obPointB:Point = new Point(m_obPointB.x , m_obPointB.y );
			var obLine:Line = new Line(obPointA , obPointB ) ;
			obLine.ofset(m_nLineOfset ) ;
			graphics.moveTo(obLine.pointA.x , obLine.pointA.y) ;
			graphics.lineStyle(m_nLineThick , m_nBackColor ) ;
			graphics.lineTo(obLine.pointB.x , obLine.pointB.y ) ;
			
		}
		
	}
}
	import flash.display.Sprite;
	import name.as3.managers.DragManager;
	import flash.events.MouseEvent;
	import name.as3.SpriteMirror.MirrorSprite;
	import name.as3.managers.RandomPosManager;
	

class ControlPoint extends Sprite 
{
	private var m_obTarget:MirrorSprite ;
	
	/**∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥构造函数
	 */	
	public function ControlPoint(obTarget:MirrorSprite ) 
	{
		super() ;
		m_obTarget = obTarget ;
		var obManager:DragManager = new DragManager(this,updateMirror) ;
		var posManager:RandomPosManager = new RandomPosManager(this) ;
		
	}
	/**
	 *∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥宽度覆盖函数 
	 * @param value
	 * 
	 */	
	public override function set width(value:Number):void
	{
		graphics.clear();
		graphics.beginFill(0x0000ff ) ;
		graphics.drawCircle(0,0,value  ) ;
	}
	/**
	 *∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥高度覆盖函数 
	 * @param value
	 * 
	 */	
	public override function set height(value:Number):void
	{
		
	}
	/**
	 *∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥∥镜面更新函数 
	 * @param e
	 * 
	 */	
	private function updateMirror(e:MouseEvent):void
	{
		if(m_obTarget!=null)
		{
			m_obTarget.updateMirror() ;
		}
	}
}